package com.rocksea.app.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import com.rocksea.app.R;
import com.rocksea.app.tasks.Temp;

/**
 * Created by 吴志华 on 2017/10/26.
 *
 * @FileName:com.rocksea.app.activity.LowStrainActivity.java
 */

public  abstract class BaseShowActivity extends AppCompatActivity
{
    public static final String INFO_EXTRA_KEY = "com.rocksea,app.PileInfoActivity.info";
    public static final String PLAN_NUM_KEY = "PLAN_NUM_KEY";
    public static final String PLIE_NO_KEY = "PLIE_NO_KEY";
    public static final String BASEINFOID_KEY = "BASEINFOID_KEY";
    public static final String TEST_CODE_KEY = "TEST_CODE_KEY";
    public static Bundle mBundle;
    public String[] infos;
    public ViewPager mViewPager;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inpse_from_v1);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar!=null){
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setTitle("桩信息");
        }
        mViewPager = (ViewPager) findViewById(R.id.container);
        infos = getIntent().getStringArrayExtra(INFO_EXTRA_KEY);
        initView();
        initData();
        actionBarTitle(actionBar);
        addFragment(mViewPager);
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(mViewPager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabTextColors(ContextCompat.getColor(this, R.color.gark_40), ContextCompat.getColor(this,android.R.color.white));
        tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(this, R.color.red_50));
        ViewCompat.setElevation(tabLayout, 10);
    }

    protected abstract void actionBarTitle(ActionBar actionBar);

    public abstract void initData();
    public abstract void addFragment(ViewPager viewPager);
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Temp.clear();
    }

    protected void initView()
    {

    }

}
